import 'dart:io';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:management/app/cons.dart';
import 'package:management/model/visitor_model.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:management/views/visitor/checkIn/idCard_widget.dart';
import 'package:management/views/visitor/query/row_item.dart';

///访客记录详情
class RecordDetails extends StatefulWidget {
  final Visitor? visitor;

  const RecordDetails({Key? key,  this.visitor}) : super(key: key);
  @override
  _RecordDetailsState createState() => _RecordDetailsState();
}

class _RecordDetailsState extends State<RecordDetails>
    with SingleTickerProviderStateMixin {
  late Visitor visitor;
  String filePath = "";

  @override
  void initState() {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // visitor = ModalRoute.of(context).settings.arguments;
    visitor = widget.visitor!;

    ///保存照片的路径
    filePath = "/sdcard/idCardPic/${visitor.IDNumber}.jpg";
    filePath = File(filePath).existsSync() ? filePath : "";

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.black26,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            size: 35,
          ),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(
          "详情",
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 25,
          ),
        ),
        centerTitle: true,
        actions: [
          IconButton(
              icon: Icon(Icons.home),
              iconSize: 50,
              onPressed: () => Navigator.of(context)
                  .pushNamedAndRemoveUntil('/HomePage', (route) => false)),
        ],
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() => ListView(
        children: [
          Container(
            padding: EdgeInsets.only(top: 20, right: 20, left: 20, bottom: 10),
            color: Colors.black12,
            child: _buildVisitorInfo(),
          ),
          Container(
            padding: EdgeInsets.only(top: 10, right: 20, left: 20, bottom: 10),
            color: Colors.black12,
            child: _buildInterviewee(),
          ),
          Container(
            padding: EdgeInsets.only(top: 10, right: 20, left: 20, bottom: 10),
            color: Colors.black12,
            child: _buildVisitorReason(),
          ),
          Container(
            padding: EdgeInsets.only(top: 10, right: 20, left: 20, bottom: 10),
            color: Colors.black12,
            child: _buildRegistrationStatus(),
          ),
        ],
      );

  //访客信息
  Widget _buildVisitorInfo() => Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              Strings.visitorInformation,
              style: TextStyle(
                fontSize: 20.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
            Container(
              padding: EdgeInsets.all(20.w),
              width: 0.9.sw,
              height: 0.62.sh,
              decoration: BoxDecoration(
                border: Border.all(color: Colors.grey, width: 2.w),
                borderRadius: BorderRadius.circular(12.w),
                color: Colors.white,
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 280.w,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          width: 1250.w,
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                height: 50.w,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      Strings.visitName,
                                      style: TextStyle(
                                        fontSize: 18.sp,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                    Container(
                                      width: 1150.w,
                                      child: TextField(
                                        readOnly: true,
                                        decoration: InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: visitor.name,
                                          hintStyle: TextStyle(fontSize: 18.sp),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Container(
                                height: 50.w,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      Strings.gender,
                                      style: TextStyle(
                                          fontSize: 18.sp,
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Container(
                                      width: 1150.w,
                                      child: TextField(
                                        readOnly: true,
                                        decoration: InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: visitor.gender,
                                          hintStyle: TextStyle(fontSize: 18.sp),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Container(
                                height: 50.w,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      Strings.nationality,
                                      style: TextStyle(
                                          fontSize: 18.sp,
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Container(
                                      width: 1150.w,
                                      child: TextField(
                                        readOnly: true,
                                        decoration: InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: visitor.nationality,
                                          hintStyle: TextStyle(fontSize: 18.sp),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Container(
                                height: 50.w,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      Strings.dateOfBirth,
                                      style: TextStyle(
                                          fontSize: 18.sp,
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Container(
                                      width: 1150.w,
                                      child: TextField(
                                        readOnly: true,
                                        decoration: InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: TextUtil.isEmpty(
                                                  visitor.dateOfBirth)
                                              ? Strings.nothing
                                              : visitor.dateOfBirth,
                                          hintStyle: TextStyle(fontSize: 18.sp),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                        VisitorPhoto(
                          400.w,
                          400.h,
                          filePath: filePath,
                        )
                      ],
                    ),
                  ),
                  Container(
                    height: 50.h,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          width: 728.w,
                          child: RowItem1(
                            text: Strings.typeOfCertificate,
                            textFieldWidth: 628.w,
                            hintText: visitor.typeOfCertificate!,
                          ),
                        ),
                        Container(
                          width: 928.w,
                          child: RowItem1(
                            text: Strings.idNumber,
                            textFieldWidth: 828.w,
                            hintText: TextUtil.isEmpty(visitor.IDNumber!)
                                ? Strings.nothing
                                : visitor.IDNumber!,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    height: 50.h,
                    child: RowItem1(
                      text: Strings.telephoneNum,
                      textFieldWidth: 1585.w,
                      hintText: TextUtil.isEmpty(visitor.telephoneNum)
                          ? Strings.nothing
                          : visitor.telephoneNum!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    child: RowItem1(
                      text: Strings.visitorAddress,
                      textFieldWidth: 1585.w,
                      hintText: TextUtil.isEmpty(visitor.visitorAddress)
                          ? Strings.nothing
                          : visitor.visitorAddress!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    child: RowItem1(
                      text: Strings.visitorUnit,
                      textFieldWidth: 1585.w,
                      hintText: TextUtil.isEmpty(visitor.visitorUnit)
                          ? Strings.nothing
                          : visitor.visitorUnit!,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      );

  //被访人
  Widget _buildInterviewee() => Container(
        child: RowItem2(
          text: Strings.interviewee,
          width: 0.9.sw,
          height: 0.1.sh,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Container(
                height: 50.h,
                // width: 800.w,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      width: 828.w,
                      child: RowItem1(
                        text: Strings.departmentInterviewed,
                        textFieldWidth: 728.w,
                        hintText:
                            TextUtil.isEmpty(visitor.departmentInterviewed)
                                ? Strings.nothing
                                : visitor.departmentInterviewed!,
                      ),
                    ),
                    Container(
                      width: 828.w,
                      child: RowItem1(
                        text: Strings.interviewee,
                        textFieldWidth: 728.w,
                        hintText: TextUtil.isEmpty(visitor.interviewee)
                            ? Strings.nothing
                            : visitor.interviewee!,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      );

  //访问事由
  Widget _buildVisitorReason() => Container(
        child: RowItem2(
          text: Strings.visitReason,
          width: 0.9.sw,
          height: 0.1.sh,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.visitMatter,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.visitingMatters)
                          ? Strings.nothing
                          : visitor.visitingMatters!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.remarks,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.remarks)
                          ? Strings.nothing
                          : visitor.remarks!,
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
      );

  //登记情况
  Widget _buildRegistrationStatus() => Container(
        child: RowItem2(
          text: Strings.registrationStatus,
          width: 0.9.sw,
          height: 0.21.sh,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.whatToBring,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.whatToBring)
                          ? Strings.nothing
                          : visitor.whatToBring!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.licensePlateNumber,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.licensePlateNumber)
                          ? Strings.nothing
                          : visitor.licensePlateNumber!,
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.numberOfAccompanyingVisitors,
                      textFieldWidth: 728.w,
                      hintText:
                          TextUtil.isEmpty(visitor.numberOfAccompanyingVisitors)
                              ? "0"
                              : visitor.numberOfAccompanyingVisitors!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.registrationPoint,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.registrationPoint)
                          ? Strings.nothing
                          : visitor.registrationPoint!,
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.registrationDate,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.registrationDate)
                          ? Strings.nothing
                          : visitor.registrationDate!,
                    ),
                  ),
                  Container(
                    height: 50.h,
                    width: 828.w,
                    child: RowItem1(
                      text: Strings.checkInTime,
                      textFieldWidth: 728.w,
                      hintText: TextUtil.isEmpty(visitor.checkInTime)
                          ? Strings.nothing
                          : visitor.checkInTime!,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      );

  @override
  void dispose() {
    super.dispose();
  }
}
